<?php
if ( !isGod() )
	die('Không có quyền truy cập vào trang này !');

include('vsGrid.php');
//them vao cac module moi
$dh  = opendir($info['module_path']);
while (false !== ($filename = readdir($dh))) 
{
	if ( filetype($info['module_path'] . $filename) == 'dir' && $filename != '.' && $filename != '..' )
	{
		//la thu muc -> xem do la mot module
		//kiem tra xem trong db da co hay chua -> neu chua co -> insert vao
		//co roi -> bo qua
		$sql = "select modname from um_module where modname='$filename' limit 0,1";
		$rs = $link->execute($sql);
		if ( $rs->EOF )	//chua co
		{
			//insert va db
			$sql = "insert into um_module(modname,moddesc,enabled) values('$filename','$filename',1)";
			$link->execute($sql);
		}		
	}
}
closedir($dh);
//xoa cac module kg su dung
$rs = $link->execute("SELECT * FROM um_module");
while(!$rs->EOF)
{
	if ( !file_exists($info['module_path'] . $rs->fields('modname') ) )	//kg co module trong thu muc module
		$link->execute("DELETE FROM um_module WHERE modname='" . $rs->fields('modname') . "'");
		
	$rs->movenext();
}

function toCheckbox($val)
{
	if ( $val != 0 )
		return '<input type="checkbox" checked disabled="true">';
	else
		return '<input type="checkbox" disabled="true">';
}

$grd = new vsGrid($link,$server['mysql_db_name'],'um_module','SELECT * FROM um_module WHERE modname NOT IN ("Index")');
$grd->selectionRow = true;
$grd->setFixCol();
$grd->arrHeader = array('Tên module','Mô tả','Kích hoạt');
$grd->arrFieldName = array('modname','moddesc','enabled,center'=>'toCheckbox');
$grd->arrAction = array('
<img src="images/check.gif" border="0" align="absmiddle" alt="Ngừng kích hoạt">'=>'admin.php?mod=Free&act=active_module&free=yes',
'<img src="images/edit_trans.gif" border="0" align="absmiddle" alt="Hiệu chỉnh">'=>'admin.php?mod=Free&act=edit_module&free=yes'
);
$grd->arrParams = array('modname'=>'modname,f','modname'=>'modname,f');
$grd->grdRender();
?>